<template>
  <div id="login">
    <h2>2024-2025学年广东省职业院校技能大赛</h2>
    <h2>（中职组）舞蹈表演赛项计分系统</h2>
    <div class="content">
      <div class="left">
        <!-- <div class="welcome">
          <p>欢迎登陆</p>
          <p>———</p>
          <h2>welcome</h2>
        </div> -->
        <!-- <img src="../../assets/img/bluebackground.png" alt="" /> -->
      </div>
      <div class="right">
        <h2 class="title">欢迎登录</h2>
        <div class="form-el">
          <el-form
            ref="formref"
            :rules="rules"
            :model="ruleForm"
            label-width="80px"
            class="demo-ruleForm"
          >
            <el-form-item prop="account" label="">
              <!-- <i class="icon"> <img src="../../assets/img/1.png" alt="" /></i> -->
              <span style="width:1px:height:80%;"></span>
              <el-input placeholder="账号" v-model="ruleForm.account" clearable>
              </el-input>
            </el-form-item>
            <el-form-item prop="password" label="">
              <!-- <i class="icon"> <img src="../../assets/img/2.png" alt="" /></i> -->
              <el-input
                placeholder="密码"
                show-password
                v-model="ruleForm.password"
                type="password"
              >
              </el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="login" @click="submit(formref)">登录</div>
      </div>
    </div>
    <div class="copyright">
      <!-- <p>
        <span v-for="item in loginInfo.footerList" :key="item">{{ item }}</span>
      </p>
      <p>
        <span v-for="item in loginInfo.otherInfo" :key="item">{{ item }}</span>
      </p> -->
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElMessage } from "element-plus";
import { onMounted, ref, reactive } from "vue";
import { login } from "../../api/api";
import { useRouter } from "vue-router";
let $router = useRouter();
let ruleForm = reactive({ account: "", password: "" });
let rules = reactive({
  account: [{ required: true, message: "请输入账号", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
});

const formref = ref();
const submit = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate((valid: any, fields: any) => {
    if (valid) {
      login({ account: ruleForm.account, password: ruleForm.password }).then(
        (res: any) => {
          if (res.code == 200) {
            ElMessage.success("登陆成功");
            localStorage.setItem("token", res.token);
            $router.push("/home");
          } else {
            ElMessage.error(res.msg);
          }
        }
      );
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>

<style lang="less" scoped>
html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
}

#login {
  background: url(../../assets/loginbg.png) no-repeat;
  width: 100%;
  height: 100vh;
  background-size: 100% 100%;
  padding-top: 4rem;

  h2 {
    text-align: center;
    color: white;
    font-size: 1.625rem;
  }

  .content {
    box-shadow: 2px 2px 20px #4d73fe56;
    position: fixed;
    width: 43.75rem;
    height: 25rem;
    background: url("../../assets/bg.png");
    background-size: 100% 100%;
    transform: translate(-50%);
    left: 50%;
    top: 25%;

    .left {
      width: 50%;
      height: 100%;
      float: left;
      position: relative;

      .welcome {
        position: absolute;
        top: 10%;
        left: 20%;
        color: white;
        font-size: 1.5rem;
        font-weight: bold;

        p {
          margin-bottom: 1.25rem;

          &:nth-child(1) {
            color: #ffe3c8;
          }
        }
      }

      img {
        width: 100%;
        height: 100%;
      }
    }

    :deep(.right) {
      width: 50%;
      height: 100%;
      // background: white;

      h2 {
        padding-top: 3.125rem;
        color: @color !important;
        text-align: center;
        margin-bottom: 3.125rem;
        font-weight: 900;
      }

      float: right;

      .el-form-item {
        width: 100%;
        margin-bottom: 1.5625rem;
        // border-radius: 20px;
        // overflow: hidden;
        // border: 1px solid #ccc;
      }

      .el-form-item__content {
        line-height: 0;
        position: relative;
        margin-left: 0 !important;
      }

      .form-el {
        width: 75%;
      }

      .el-input-group--prepend {
        // border-radius: 20px;
        // overflow: hidden;
      }

      .el-input__suffix {
        background: #ebebeb;
      }

      .el-input-group__prepend {
        background: white;
      }

      .el-input__icon {
        margin-left: 0;
        margin-right: 8px;
      }

      .el-input__inner {
        // overflow: hidden;
        // border-radius: 20px;
        border: none;
        background: #ebebeb;
        height: 2.5rem;
        padding-left: 0.625rem;
      }

      .icon {
        position: absolute;
        font-size: 18px;
        left: 0%;
        top: 50%;
        padding: 0 8px;
        border-right: 1px solid #ccc;
        transform: translateY(-50%);

        img {
          width: 70%;
          height: 70%;
          margin-left: 15%;
        }
      }

      .el-select {
        border: none;
        width: 70%;
        margin-left: 3.125rem;

        .el-input {
          width: 120% !important;
        }
      }

      .select {
        overflow: hidden;
        padding-left: 3.125rem;

        .el-input {
          width: 120% !important;
        }
      }

      .el-form {
        transform: translate(15%);

        el-from-item {
          // border-radius: 20px;
          background: #ebebeb;
        }

        .el-input {
          // width: 80%;
          height: 2.5rem;

          .el-input__wrapper {
            box-shadow: none;
            padding: 0;
          }
        }
      }

      .identify {
        display: flex;
        justify-content: space-between;
        align-items: center;
        vertical-align: top;
      }

      p {
        text-align: left;
        color: #ccc;
        opacity: 0.8;
        font-size: 12px;
      }

      .login {
        background: @color !important;
        width: 75%;
        color: white;
        height: 2.5rem;
        margin-top: 3.125rem;
        text-align: center;
        // border-radius: 20px;
        overflow: hidden;
        transform: translateX(16%);
        line-height: 2.5rem;
      }
    }
  }

  .copyright {
    width: 100%;
    color: #ccc;
    font-size: 12px;
    position: fixed;
    left: 0;
    bottom: 0;
    text-align: center;

    p {
      margin: 5px 0;
    }
  }
}
</style>
